# Maintainer:
pkgname=libkcapi
pkgver=1.4.0
pkgrel=4
pkgdesc="Linux Kernel Crypto API User Space Interface Library"
url="https://www.chronox.de/libkcapi.html"
arch="all"
license="BSD-3-Clause OR GPL-2.0-only"
makedepends="
	autoconf
	automake
	libtool
	linux-headers
	"
checkdepends="bash openssl"
subpackages="$pkgname-dev $pkgname-tools $pkgname-doc"
source="https://www.chronox.de/libkcapi/libkcapi-$pkgver.tar.xz
	no-werror.patch
	"
# requires AF_ALG support and enablement of ktls on running kernel
options="!check"

prepare() {
	default_prepare

	autoreconf -fvi
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--prefix=/usr \
		--build=$CBUILD \
		--host=$CHOST \
		--enable-kcapi-hasher \
		--enable-kcapi-speed \
		--enable-kcapi-rngapp \
		--enable-kcapi-encapp \
		--enable-kcapi-dgstapp \
		--enable-kcapi-test \
		--disable-static
	make
}

check() {
	local tests="
		hasher-test.sh
		kcapi-convenience.sh
		kcapi-dgst-test.sh
		kcapi-enc-test-large.sh
		kcapi-enc-test.sh
		kcapi-fuzz-test.sh
		"
	for test in $tests; do
		msg "testing $test"
		./test/$test
	done
}

package() {
	make DESTDIR="$pkgdir" install

	rm "$pkgdir"/usr/lib/.[!.]*
	rm "$pkgdir"/usr/bin/.[!.]*
	rm "$pkgdir"/usr/bin/fips*
	rm -r "$pkgdir"/usr/libexec/

	cd "$pkgdir"/usr/bin

	# rename generic utils to not conflict with generic names. the options
	# aren't guaranteed to be compatible
	for tool in sha* md5* sm3*; do
		mv $tool kcapi-$tool
	done
}

tools() {
	pkgdesc="$pkgdesc (commandline utilities)"

	amove usr/bin
}

sha512sums="
fa3df1fe22eba32585de5df044f907d3ad189c33f5704fe29b0fdeda92e772ef077055b80e17bc1646a8cdedaf4f195aadf0b133f493597f0f7657b04ea93a99  libkcapi-1.4.0.tar.xz
a5b38f49a7bb07eb57523566e065bad702999d8be21fa6cd8a01af1b60e9bd8fbb6fd9cf71f70dca7d616aa381475273d995841b8580f91418fb0094263e6402  no-werror.patch
"
